package com.lenovo.lcdm.integration.config;

import cn.hutool.json.JSONUtil;
import com.lenovo.lcdm.integration.entity.EndpointConfig;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public class KafkaProducerContext {

    private final static Map<String, EndpointConfig> endpointConfigMap = new ConcurrentHashMap<>();

    public static void setEndpointConfigMap(EndpointConfig endpointConfig) {
        try {
            Map<String, Object> connectionInfo = JSONUtil.parseObj(endpointConfig.getConnectionInfo());
            connectionInfo.put("ssl.truststore.location", KafkaConsumerContext.getSSlCertificatePath());
            endpointConfig.setConnectionInfo(connectionInfo);
            endpointConfigMap.put(endpointConfig.getName(), endpointConfig);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    public static EndpointConfig getEndpointConfigMap(String topic) {
        return endpointConfigMap.get(topic);
    }
}
